
//导入mongoose模块
const mongoose = require('mongoose')
//定义连接mongoDB的字符串（连接地址）
const db_url = 'mongodb://localhost:27017/Test'
//连接
mongoose.set('strictQuery', false);
mongoose.connect(db_url,{useNewUrlParser:true,useUnifiedTopology:true});

//连接成功
mongoose.connection.on('connected',function (){
    console.log('MongoDB Connection open'+db_url)
})
//连接失败
mongoose.connection.on('error',function (err){
    console.log('MongoDB Connection error:'+err)
})
//断开连接
mongoose.connection.on('disconnected',function(){
    console.log('MongoDB disconnected ')
})

module.exports = mongoose
